﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eTMS.Controllers;
using eTMS.Controllers.KhoaHocService;
using eTMS.Controllers.LopService;
using eTMS.Controllers.NganhHocService;

namespace eTMS.UserControls
{
    public partial class SearchSinhVien : eTMS.Controls.UserControlBase
    {
        public SearchSinhVien()
        {
            InitializeComponent();
        }
        private List<int> _LsHiddenSinhVien_ID = new List<int>();
        public void SetHidenList(List<int> LsSinhVien_ID)
        {
            _LsHiddenSinhVien_ID = LsSinhVien_ID;
        }
        public bool IsCheckable
        {
            set
            {
                sinhVienList1.IsCheckable = value;
            }
            get
            {
                return sinhVienList1.IsCheckable;
            }
        }
        private SinhVienController controller;
        public List<DataRow> GetSelectedSinhVienRows()
        {
            return sinhVienList1.GetSelectedSinhVienRows();
        }
        public List<DataRow> GetCheckedSinhVienRows()
        {
            return sinhVienList1.GetCheckedSinhVienRows();
        }
        public int SelectedLop_ID
        {
            get
            {
                return treeKhoaNganhKhoaHoc1.SelectedLop_ID;
            }
            set
            {
                treeKhoaNganhKhoaHoc1.SelectedLop_ID = value;
            }
        }
        public LopEntity GetSelectedLop()
        {
            return treeKhoaNganhKhoaHoc1.GetSelectedLop();
        }
        public int KhoaHoc_ID
        {
            get
            {
                return treeKhoaNganhKhoaHoc1.KhoaHoc_ID;
            }
            set
            {
                treeKhoaNganhKhoaHoc1.KhoaHoc_ID = value;
            }
        }
        public KhoaHocEntity GetKhoaHoc()
        {
            return treeKhoaNganhKhoaHoc1.GetKhoaHoc();
        }
        
        public int SelectedNganhHoc_ID
        {
            get
            {
                return treeKhoaNganhKhoaHoc1.SelectedNganhHoc_ID;
            }
        }

        private int _FilterMonHoc_ID = 0;
        public int FilterMonHoc_ID
        {
            set
            {
                _FilterMonHoc_ID = value;
            }
        }

        private int _FilterNamHoc_ID = 0;
        public int FilterNamHoc_ID
        {
            set
            {
                _FilterNamHoc_ID = value;
            }
        }

        private int _FilterHocKy_ID = 0;
        public int FilterHocKy_ID
        {
            set
            {
                _FilterHocKy_ID = value;
            }
        }
        public NganhHocEntity GetSelectedNganhHoc()
        {
            return treeKhoaNganhKhoaHoc1.GetSelectedNganhHoc();
        }
        public void UpdateToScreen()
        {
            DoSearchSinhVien();
        }
        public void SetController(SinhVienController sinhVienController)
        {
            controller = sinhVienController;
            sinhVienInfoInput1.SetController(controller);
            sinhVienList1.SetController(controller);
            treeKhoaNganhKhoaHoc1.InitData();
        }
        private void DoSearchSinhVien()
        {
            if (controller == null) return;
            controller.ResetObject();
            sinhVienInfoInput1.UpdateToModel();
            if (_FilterMonHoc_ID == 0)
            {
                controller.SearchSinhVien(treeKhoaNganhKhoaHoc1.SelectedKhoa_ID, treeKhoaNganhKhoaHoc1.SelectedNganhHoc_ID, treeKhoaNganhKhoaHoc1.SelectedLop_ID, treeKhoaNganhKhoaHoc1.KhoaHoc_ID);
            }
            else
            {
                controller.SearchSinhVienHocMonHoc(_FilterNamHoc_ID, _FilterHocKy_ID, _FilterMonHoc_ID, treeKhoaNganhKhoaHoc1.SelectedLop_ID);
            }
            if (_LsHiddenSinhVien_ID.Count > 0)
            {
                controller.Table.DefaultView.RowFilter = "SINHVIEN_ID NOT IN("+string.Join(",",_LsHiddenSinhVien_ID.ConvertAll<string>(Convert.ToString).ToArray())+")";
            }
            sinhVienList1.UpdateToScreen();
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            DoSearchSinhVien();
        }
        public void UpdateObjectToModel()
        {
            sinhVienList1.UpdateObjectToModel();
        }

        private void SearchSinhVien_Load(object sender, EventArgs e)
        {
            if (DesignMode) return;
            treeKhoaNganhKhoaHoc1.InitData();
        }

        private void treeKhoaNganhKhoaHoc1_OnChangeKhoaHoc(object sender, EventArgs e)
        {
            DoSearchSinhVien();
        }
       



    }
}
